import requests
import json
res = requests.get(url="http://localhost:8899/api/v1/proxies")
from douban.settings import IP_LIST_FILE
res = res.text

res = json.loads(res)
url = 'http://cip.cc'
for proxy in res['proxies']:
    ip = proxy['ip']
    port = proxy['port']
    is_https = proxy['is_https']

    if is_https:
        https_query_str = "https://{}:{}".format(ip,port)
    else:
        https_query_str = "http://{}:{}".format(ip,port)

    http_query_str = "http://{}:{}".format(ip,port)
    proxis_list = {
        "https": https_query_str,
        "http": http_query_str,
    }
    try:
        res = requests.get(url, proxies=proxis_list, timeout=10)
        with open(IP_LIST_FILE + "ok", 'aw') as f:
            f.write(https_query_str)
        print(https_query_str)
        print('ok')
    except Exception:
        print('error')
        pass

x = 1